<?php
namespace haibao\www\data;
use \haibao\frame\data\MysqlData;

abstract class BaseMysql extends MysqlData{
	private static $cacheObject = null;
	
	public function __construct($modelName){
		parent::__construct($modelName);
		$this->setConfig( \haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_CMS );
	}
	
	public function getCache($key){
		$cache = $this->getCacheObject();
		return $cache->get($key);
	}
	
	public function setCache($key,$value){
		$cache = $this->getCacheObject();
		$cache->set($key, $value);
	}
	
	public function unsetCache($key){
		$cache = $this->getCacheObject();
		$cache->del($key);
	}
	
	/**
	 * @return \haibao\cms\cache\FileCache
	 */
	private function getCacheObject(){
		if (!self::$cacheObject){
			self::$cacheObject = new \haibao\www\cache\FileCache();
		}
		return self::$cacheObject;
	}
	
	/**
	 * 精简数值
	 */
	public function formatNum($num){
	$num = (int)$num;
		if($num>9999){
			$num = (string)$num;
			$front = substr($num,0,-4);
			$kilobit = (int)substr($num, -4,1);
			$hundreds = (int)substr($num, -3,1);
			$preTmpNum =  $front.'.'.$kilobit;
			$preNum = $hundreds > 4? $preTmpNum+0.1 : $preTmpNum;
			return $preNum.'万';
		}else{
			return $num;
		}
	}
}